package com.example.blog.service.impl;

import com.example.blog.mapper.ArticleMapper;
import com.example.blog.po.Article;
import com.example.blog.service.IArticleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ArticleServiceImpl implements IArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Cacheable(cacheNames = "Articles")
    public PageInfo<Article> getPagedArticles(Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<Article> articles = articleMapper.selectAll();
        if(articles == null){
            articles = Collections.emptyList();
        }

        PageInfo<Article> pageInfo = PageInfo.of(articles);

        return pageInfo;
    }



}
